import { Controller, Post, Get, Body } from "@nestjs/common";
import { ApiRes, UsePermGuard, definePermission } from "src/decorator";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { PermissionEntity } from "src/entity";
import { PerimssionService } from "../service/permission.service";
import { Perm as RolePerm } from "./role.controller";
import { PermissionQueryDto } from "src/dto/permission";

const Perm = definePermission("permission", {
    query: {
        name: "查询",
        code: "query",
        description: "权限查询权限",
    },
} as const);

@ApiTags("Permission - 模块")
@Controller("permission")
export class PermissionController {
    constructor(private readonly perimssionService: PerimssionService) {}

    @ApiOperation({ summary: "权限列表" })
    @ApiRes({ type: PermissionEntity, pagination: true })
    @UsePermGuard(Perm.QUERY, RolePerm.ADD, RolePerm.UPDATE)
    @Post("query")
    permissionList(@Body() dto: PermissionQueryDto) {
        return this.perimssionService.query(dto);
    }
}
